<!DOCTYPE html>

<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="user-scalable=no, width=device-width"/>
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.structure-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.inline-png-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.inline-svg-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.external-png-1.4.4.min.css">
        <!-- Choix du thème -->
        <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
        <link rel="stylesheet" href="css/bootstrap/jquery.mobile.icons.min.css">
        <!-- JavaScript -->
        <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.4.4.min.js"></script>
        <script type="text/javascript" src="js/datebox/jqm-datebox.core.js"></script>
        <script type="text/javascript" src="js/datebox/jqm-datebox.mode.datebox.js"></script>
        <title></title>
    </head>
    <body>
        <div data-role="page" id="Projet"  data-dom-cache=true>

            <?php
            session_start();
            $idUser = $_SESSION["id"];
            // echo "$idUser";


            $prevlink = 'accueil.php';
            $headerText = 'Liste des projets';
            include 'includes/header.php';
            ?>

            <div data-role="content">
                <?php
                // Montrer les erreurs
                ini_set('display_errors', 1);
                ini_set('display_startup_errors', 1);
                error_reporting(-1);
                require_once '../controller/AbonProjetManager.php';
                require_once '../controller/ProjetManager.php';
                include_once '../model/config.php';
                require_once '../model/AbonProjet.php';


                // $list = $manager->getList();

                if (isset($_POST['valider']) && !empty($_POST['choix'])) {
                    $var = $_POST['choix'];
                    $manager = new ProjetManager($bdd);
                    foreach ($var as $valeur) {

                        $list2 = $manager->getList($valeur);

                        foreach ($list2 as $projet) {
                            $libelle = $projet->getLibelleProjet();
                            $id = $valeur;
                            $commentaire = "Abonnement";
                            $user = $idUser;
                        }
                        $abonProjet = new AbonProjet($id, $user, $libelle, $commentaire);

                        $manager2 = new AbonProjetManager($bdd);
                        $manager2->add($abonProjet);
                    }
                }




                $manager3 = new AbonProjetManager($bdd);
                $list3 = $manager3->getListAbonProjet($idUser);
                //echo '<ul data-role="listview">';
                foreach ($list3 as $abonProjet) {
                    $libelle = utf8_encode($abonProjet->getLibelle());
                    $id = $abonProjet->getIdProjet();
                    //echo '<li>';
                    echo '<a data-transition=flip href="tacheSeance.php?idProjet=' . $id . '" data-role="button">';
                    echo $libelle;
                    echo '</a>';
                    //echo '<span class="ui-li-count">2 </span>';
                    // echo '</li>';
                }
                // echo '</ul>';
                //  }
                ?>

                <a href="choixClasse.php" data-role="button" data-icon="plus" data-transition="flip" data-theme="b"> Ajouter des projets </a> 
            </div>

            <div data-role="footer" data-theme="e" data-position="fixed" >
                <h1> &copy INSA TOULOUSE</h1>
            </div>
        </div>

    </body>
</html>
